﻿package mortal.game.view.guildNew.mercenary
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import fl.data.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.mvc.core.*;

    public class GuildNewMercenaryPanel extends GSprite
    {
        protected var _bg:ScaleBitmap;
        protected var _title:GuildNewMercenaryTitle;
        protected var _list:GTileList;
        protected var _operPanel:GuildNewMercenaryOperPanel;
        protected var _perInfo:GuildNewMercenaryPerInfo;
        private var _sortFunction:Function;

        public function GuildNewMercenaryPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.guildNewMercenary, this.onShow);
            return;
        }// end function

        private function onShow() : void
        {
            this._bg = UIFactory.bg(0, 0, 754, 375, this, ImagesConst.PanelBg);
            this._list = UIFactory.tileList(7, 26, 745, 350, this);
            this._list.direction = GBoxDirection.VERTICAL;
            this._list.verticalGap = 0;
            this._list.horizontalGap = 2;
            this._list.rowHeight = 35;
            this._list.columnWidth = 730;
            this._list.columnCount = 1;
            this._list.rowCount = 10;
            this._list.width = 745;
            this._list.setStyle("cellRenderer", GuildNewMercenaryCell);
            this._title = UIFactory.getUICompoment(GuildNewMercenaryTitle, 0, 1, this);
            this._perInfo = UIFactory.getUICompoment(GuildNewMercenaryPerInfo, 0, 372, this);
            this._operPanel = UIFactory.getUICompoment(GuildNewMercenaryOperPanel, 366, 372, this);
            this.reqList();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._title = null;
            this._operPanel = null;
            this._perInfo = null;
            this._bg = null;
            this._list = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function reqList() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(GuildNewLocalEvent.GuildNewMercenaryGetInfo));
            return;
        }// end function

        public function update() : void
        {
            return;
        }// end function

        public function updateList() : void
        {
            var _loc_1:* = Cache.instance.guild.selfGuildInfo.mercenaryArr;
            _loc_1 = this.filterArr(_loc_1);
            this._sortFunction = this._title.sortFunction;
            if (this._sortFunction == null)
            {
            }
            else if (_loc_1.length > 1)
            {
                _loc_1.sort(this._sortFunction);
            }
            var _loc_2:* = new DataProvider(_loc_1);
            this._list.dataProvider = _loc_2;
            this.updateTimes();
            this.updateCanGetGoin();
            return;
        }// end function

        private function filterArr(param1:Array) : Array
        {
            var _loc_4:SGuildMercenary = null;
            if (param1 == null)
            {
                return param1;
            }
            var _loc_2:Array = [];
            var _loc_3:int = 0;
            while (_loc_3 < param1.length)
            {
                
                _loc_4 = param1[_loc_3];
                if (_loc_4.count < GuildNewMercenaryProcessor.oneDayTimes && this.notPassTime(_loc_4))
                {
                    _loc_2.push(_loc_4);
                }
                _loc_3++;
            }
            return _loc_2;
        }// end function

        private function notPassTime(param1:SGuildMercenary) : Boolean
        {
            if (param1 == null)
            {
                return false;
            }
            var _loc_2:* = ClockManager.instance.nowDate;
            var _loc_3:* = (param1.creatdt.time - _loc_2.time) / 1000;
            return _loc_3 > 0;
        }// end function

        public function updateCanGetGoin() : void
        {
            return;
        }// end function

        private function updateTimes() : void
        {
            return;
        }// end function

        private function updateSelfInfo() : void
        {
            return;
        }// end function

    }
}
